package com.sicheng.lc.lc笔试.美团篇;

import java.util.HashSet;
import java.util.Objects;
import java.util.Scanner;
import java.util.Set;

/**
 * @author zsc
 * @version 1.0
 * @date 2022/8/20 10:13
 */
public class 曼哈顿 {
    /**
     * 曼哈顿距离 d[a,b]=abs(ax-bx)+abs(ay-by)
     * 所有点坐标范围[1,n]
     * 给定3个点啊，a,b,c 找一个 p 他们到p的曼哈顿距离为 u,v,w
     * 输入说明
     * 第一行 :   n
     * 第二行 :   ax ay bx by cx cy
     * 第三行 :   u v w
     */
    static class Node {
        int x, y;

        public Node(int x, int y) {
            this.x = x;
            this.y = y;
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;
            Node node = (Node) o;
            return x == node.x && y == node.y;
        }

        @Override
        public int hashCode() {
            return Objects.hash(x, y);
        }
    }

    static Set<Node> man(int x, int y, int n, int a) {
        HashSet<Node> set = new HashSet<>();
        for (int i = 0; i <= a; i++) {
            int p = x + i;
            int q = y + a - i;
            if (p >= 1 && q >= 1 && p <= n && q <= n) {
                set.add(new Node(q, p));
            }

            int p0 = 2 * x - p, q0 = q;
            if (p0 >= 1 && q0 >= 1 && p0 <= n && q0 <= n) {
                set.add(new Node(p0, q0));
            }

            p0 = p;
            q0 = 2 * y - q;
            if (p0 >= 1 && q0 >= 1 && p0 <= n && q0 <= n) {
                set.add(new Node(p0, q0));
            }
            p0 = 2 * x - p;
            q0 = 2 * y - q;
            if (p0 >= 1 && q0 >= 1 && p0 <= n && q0 <= n) {
                set.add(new Node(p0, q0));
            }
        }
        return set;
    }


    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int x1 = in.nextInt();
        int y1 = in.nextInt();
        int x2 = in.nextInt();
        int y2 = in.nextInt();
        int x3 = in.nextInt();
        int y3 = in.nextInt();
        int[] d = new int[3];
        for (int i = 0; i < d.length; i++) {
            d[i] = in.nextInt();
        }

        Set<Node> set1 = man(x1, y1, n, d[0]);
        Set<Node> set2 = man(x2, y2, n, d[1]);
        Set<Node> set3 = man(x3, y3, n, d[2]);

        int x = 0x7ffffff, y = 0x7ffffff;
        for (Node node : set1) {
            if (set2.contains(node) && set3.contains(node)) {
                int i = node.x;
                int j = node.y;
                if (x == 0x7ffffff || i < x || (i == x && j < y)) {
                    x = i;
                    y = j;
                }
            }
        }
        System.out.printf("%d %d", x, y);
    }
}
